//
//  CJOriginalTableViewCell.m
//  KaiJing
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "CJOriginalTableViewCell.h"
#import <UIButton+WebCache.h>
@implementation CJOriginalTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
  
        _imageButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _imageButton.frame = CGRectMake((kScreenWidth - 180) / 2, 10, 180, 180);
        [_imageButton setImage:[UIImage imageNamed:@"close_2"] forState:(UIControlStateNormal)];
        [_imageButton setImage:[UIImage imageNamed:@"open_1"] forState:(UIControlStateSelected)];
        _imageButton.layer.cornerRadius = 90;
        _imageButton.layer.masksToBounds = YES;
        _imageButton.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_imageButton];
        
        
        //标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _imageButton.bottom + 10, kScreenWidth - 20, 40)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = -1;
        _titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:_titleLabel];
        
        
        //内容
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, 70)];
        _contentLabel.textAlignment = NSTextAlignmentCenter;
        _contentLabel.numberOfLines = -1;
        _contentLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_contentLabel];
        
        
        //下面视图集合
        _bottomView = [[CJCellBottomView alloc] initWithFrame:CGRectMake(0, _contentLabel.bottom + 25, kScreenWidth, 25)];
        [self.contentView addSubview:_bottomView];
        
        //点赞
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_norml"] forState:(UIControlStateNormal)];
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_select"] forState:(UIControlStateSelected)];
        _bottomView.praiseLabel.text = @"赞";
        //评论
        [_bottomView.commentButton setImage:[UIImage imageNamed:@"comment"] forState:(UIControlStateNormal)];
        _bottomView.commentLabel.text = @"评论";
        
        //更多
        [_bottomView.moreButton setImage:[UIImage imageNamed:@"more"] forState:(UIControlStateNormal)];
        
    }
    return self;
}


- (void)setModel:(HYMoreShortModel *)model {
    
    _model = model;
    
  
    NSString *urlStr = [NSString stringWithFormat:@"http://morguo.com/%@",_model.image];
    [_imageButton sd_setBackgroundImageWithURL:[NSURL URLWithString:urlStr] forState:(UIControlStateNormal)];
    
    _titleLabel.text = _model.subject;
    CGFloat height = [CJOriginalTableViewCell cellOfContentLabelHeight:_model];
    _contentLabel.frame = CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, height);
    _contentLabel.text = _model.intro;
    
    _bottomView.frame = CGRectMake(0, _contentLabel.bottom + 25, kScreenWidth, 25);
    
}




+(CGFloat)cellOfContentLabelHeight:(HYMoreShortModel *)model
{
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    
    CGRect frame = [model.intro boundingRectWithSize:CGSizeMake(kScreenWidth - 20, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    
    return frame.size.height;
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
